package com.hfzy.ihk.web.callhistoryold.biz;


import com.hfzy.ihk.common.core.elasticsearch.service.EsBaseServiceImpl;
import com.hfzy.ihk.web.callhistoryold.dao.PhoneDataRepository;
import com.hfzy.ihk.web.callhistoryold.entity.PhoneData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class PhoneDataBiz extends EsBaseServiceImpl<PhoneData> {

    @Override
    protected ElasticsearchCrudRepository getReposity() {
        return phoneDataRepository;
    }

    @Autowired
    PhoneDataRepository phoneDataRepository;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 根据号码获取归属地
     * @param phone
     * @return
     */
    List<String> getPhoneDataByPhoneLike(String phone){
        RowMapper<PhoneData> rowMapper = (RowMapper<PhoneData>) BeanPropertyRowMapper
                .newInstance(PhoneData.class);
        String sql = "select city from mydba2.phone_location  where phone_no like '" + phone + "%'";
        return jdbcTemplate.queryForList(sql,String.class);
    }

}
